import com.itmayiedu.main.threadpool.impl.MyConnectionPool;

import java.sql.Connection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Mymain {
    public static void main(String[] args) {
        /**
        创建线程池
         弹性
         固定数量
         指定数量
         定时
         不阻塞
         forkjoin
         */
        MyConnectionPool myConnectionPool=new MyConnectionPool();
        ExecutorService service = Executors.newFixedThreadPool(3);
        for (int i=0;i<3;i++){
            service.submit(()->{
                for (int j = 0; j < 10; j++) {
                    try {
                        Connection connection =myConnectionPool.getConnection();
                        System.out.println(Thread.currentThread().getName() + ",connection:" + connection);
                        myConnectionPool.releaseConnection(connection);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
}
